using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace CMSApplication.Models.Mapping
{
    public class SiteMap : EntityTypeConfiguration<Site>
    {
        public SiteMap()
        {
            // Primary Key
            this.HasKey(t => t.site_id);

            // Properties
            this.Property(t => t.site_url)
                .HasMaxLength(50);

            this.Property(t => t.site_title)
                .HasMaxLength(50);

            this.Property(t => t.site_desc)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("Sites");
            this.Property(t => t.site_id).HasColumnName("site_id");
            this.Property(t => t.site_url).HasColumnName("site_url");
            this.Property(t => t.site_title).HasColumnName("site_title");
            this.Property(t => t.site_desc).HasColumnName("site_desc");
            this.Property(t => t.version_id).HasColumnName("version_id");

            // Relationships
            this.HasRequired(t => t.Version)
                .WithMany(t => t.Sites)
                .HasForeignKey(d => d.version_id);

        }
    }
}
